<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button>点击</button>
    <div></div>
    <script>
        var btn = document.querySelector('button');
        btn.addEventListener('click', function() {
            location.href = 'http://www.itcast.cn';
        })
        var div = document.querySelector('div');
        var timer = 5;
        fn();

        //五秒后跳转页面
        function fn() {
            if (timer == 0) {
                location.href = 'http://www.csdn.net';
            } else {
                div.innerHTML = '您将在' + timer + '跳转到CSDN';
                timer--;
            }
        }

        setInterval(fn, 1000)
    </script>
</body>

</html>